import React from 'react';
import { Event } from '../utils';

export function useEventEffect<T = any>(
  event: Event<T>,
  listener: (args: T) => void,
  dependencies: any[] = []
) {
  React.useEffect(() => {
    const disposable = event(listener);
    return disposable.dispose.bind(disposable);
  }, dependencies);
}
